package com.wf.day_0603.test4;

import java.util.*;

public class PlayGame {
    static Map<Integer, String> hs = getCards();


    public static void main(String[] args) {


        List<Integer> introduction = new ArrayList<>(hs.keySet());

        Collections.shuffle(introduction);

        List<Integer> player1 = new ArrayList<>();
        List<Integer> player2 = new ArrayList<>();
        List<Integer> player3 = new ArrayList<>();
        List<Integer> upCards = new ArrayList<>();

        for (int i = 0; i < introduction.size(); i++) {
            if (i >= 51) {
                upCards.add(introduction.get(i));
            }
            if (i % 3 == 0) {
                player1.add(introduction.get(i));
            } else if (i % 3 == 1) {
                player2.add(introduction.get(i));
            } else {
                player3.add(introduction.get(i));
            }
        }

        System.out.println("----------------摸牌后-----------------");
        getP("张三的牌为:", player1);
        getP("李四的牌为:", player2);
        getP("王五的牌为:", player3);
        getP("底牌牌为:", upCards);

        System.out.println("-------------分发底牌后-----------------");

        disUpCards(player1, upCards);
        disUpCards(player2, upCards);
        disUpCards(player3, upCards);
        getP("张三的牌为:", player1);
        getP("李四的牌为:", player2);
        getP("王五的牌为:", player3);


    }

    private static void disUpCards(List<Integer> player1, List<Integer> upCards) {
        if (player1.stream()
                .map(hs::get).anyMatch(a -> a.equals("大王"))) {
            player1.addAll(upCards);

        }
    }


    public static HashMap<Integer, String> getCards() {
        HashMap<Integer, String> cards = new HashMap<>();
        String colors = "♥-♠-♣-♦";
        String[] color = colors.split("-");
        String numbers = "2-A-K-Q-J-10-9-8-7-6-5-4-3";
        String[] number = numbers.split("-");
        int count = 2;

        for (String string : number) {
            for (String s : color) {
                cards.put(count, s + string);
                count++;
            }
        }
        cards.put(0, "大王");
        cards.put(1, "小王");

        return cards;
    }

    public static void getP(String s, List<Integer> number) {

        System.out.print(s);
        number.stream()
                .sorted()
                .map(i -> hs.get(i))
                .forEach(string -> System.out.print(string + " "));
        System.out.println();


    }
}
